package com.example.ckycode.servlet;

import com.example.skycode.dao.NewsDao;
import com.example.skycode.dao.AdminDao;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
@@ -10,17 +10,25 @@ import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/adminDel.jsp")
public class AdminDelServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        int newsId = Integer.parseInt(req.getParameter("AdminId"));
        int result = (new NewsDao().delete(newsId));
        if (result > 0) {
            resp.sendRedirect("news.jsp");
        } else {
            req.setAttribute("msg", "更新失败");// 错误页面显示的内容
            req.setAttribute("url", "news.jsp");// 显示错误信息后要跳转的页面
            req.getRequestDispatcher("WEB-INF/error.jsp").forward(req, resp);
            public class AdminDelServlet extends HttpServlet {
                @Override
                protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
                    String user = (String) req.getSession().getAttribute("User");//获取会话
                    if (user == null || user.equals("")) {
                        resp.sendRedirect("login.jsp");//没登录 跳转到登陆页面
                        return;
                    }
                    int AdminId = Integer.parseInt(req.getParameter("AdminId"));
                    int result = (new AdminDao()).delete(AdminId);
                    if (result > 0) {
                        resp.sendRedirect("admin.jsp");
                    } else {

                        req.setAttribute("msg", "删除失败");
                        req.setAttribute("url", "admin.jsp");
                        req.getRequestDispatcher("WEB-INF/error.jsp").forward(req, resp);
                    }

                }
            }
        }
    }
}
